﻿using Modules.System.Attachment;
using PetaPoco;
using PmSoft;
using PmSoft.Caching;
using System.ComponentModel;
using static Modules.Notify.NotifyConstants;

namespace Modules.Entitys
{
    /// <summary>
    /// 通知附件关联表
    ///</summary>
    [TableName("notify_attachment")]
    [Description("通知附件表")]
    [PrimaryKey("id", AutoIncrement = true)]
    [CacheSetting(true, PropertyNamesOfArea = "NotifyId")]
    [Serializable]
    public class NotifyAttachment : IDelEntity, IAttachmentRelationship
    {
        /// <summary>
        ///
        ///</summary>
        [Column("id")]
        public int Id { get; set; }

        /// <summary>
        /// 附件Id
        ///</summary>
        [Column("attachment_id")]
        public string AttachmentId { get; set; }

        /// <summary>
        /// 通知Id
        ///</summary>
        [Column("notify_id")]
        public string NotifyId { get; set; }

        /// <summary>
        /// 附件类型 1：系统通知 2：工人通知
        ///</summary>
        [Column("attachment_type")]
        public 通知类型 AttachmentType { get; set; }
        /// <summary>
        /// 是否已删除
        /// 默认值: b'0'
        ///</summary>
        [Column("is_deleted")]
        public bool IsDeleted { get; set; }
        /// <summary>
        /// 修改时间
        ///</summary>
        [Column("create_time")]
        public DateTime CreateTime { get; set; } = DateTime.Now;

        [Ignore]
        string IAttachmentRelationship.BucketName => "notify";

        [Ignore]
        string IAttachmentRelationship.Directory => (AttachmentType == 通知类型.系统通知 ? "system" : "worker") + "/" + NotifyId.ToString();

        [Ignore]
        string IAttachmentRelationship.AttachmentId => AttachmentId;
        [Ignore]
        bool IDelEntity.IsDeletedInDatabase { get => IsDeleted; set => IsDeleted = value; }

        #region IEntity 成员

        [Ignore]
        object IEntity.EntityId { get { return this.Id; } }

        #endregion IEntity 成员
    }
}